<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="./js/jquery-3.7.1.min.js"></script>
    <title>图片小程序</title>
    <style>
        #test1 { 
           text-align: center;
        }
        #test1 input { 
            width: 200px;
            height: 50px;
        }
    </style>
</head>
<body>
    <div id="test1">
        <div id="demo2"><h2>猴子</h2></div>
        <div id="demo1"> <img src="./img/monkey.png" width="200px"> </div>
        <input type="button" value="缩小" id="btn1">
        <input type="button" value="放大" id="btn2">
        <input type="button" value="换一张" id="btn3">
    </div>


    <script>
        $("#btn1").click(function(){
            let img = $("#demo1 img").attr("width");
            let imgcount = parseInt(img);
            $("#demo1 img").attr("width",(imgcount - 20) + "px");
        });
        $("#btn2").click(function(){
            let img = $("#demo1 img").attr("width");
            let imgcount = parseInt(img);
            $("#demo1 img").attr("width",(imgcount + 20) + "px");
        });
        
        //定义图片数组
        let imgArray = ["./img/monkey.png","./img/mouse.png","./img/tiger.png","./img/pig.png"];
        let imgInt = 0;

        //定义描述数组
        let desArray = ["猴子","老鼠","老虎","猪"];
        let Int = 0;

        $("#btn3").click(function(){
            imgInt = (imgInt + 1) % imgArray.length;
            $("#demo1 img").attr("src",imgArray[imgInt]);

            Int = (Int + 1) % desArray.length;
            $("#demo2 h2").text(desArray[Int]);
        });

    </script>
    
</body>
</html>